package com.cssw.fyzb.core.dao.video;


import com.cssw.fyzb.core.model.dodb.CmfUserVideo;
import com.ydn.dbframe.plugin.activerecord.Db;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.Map;

/**
 * @Auther: zzf
 * @Date: 2020/12/3 16:27
 * @Description:
 */
@Repository
public class CmfUsersVideoDaoImpl implements CmfUsersVideoDao {

    @Override
    public Page<CmfUserVideo> list(int page, int limit, Map param) {
        SqlParse sql = new SqlParse(param);
        sql.addSQL("select t1.*, t2.user_name, t2.nick_name ");
        sql.addSQL(" ,(select count(*) from cmf_user_video_favorite t3 where t3.user_id=t1.user_id)favorite_count");
        sql.addSQL(" ,(select count(*) from cmf_user_video_like t3 where t3.user_id=t1.user_id )like_count");
        sql.addSQL(" ,(select count(*) from cmf_user_video_view t3 where t3.user_id=t1.user_id )view_count");
        sql.addSQL(" from cmf_user_video t1 left join t_user t2 on t2.user_id=t1.user_id  where 1=1 ");
        sql.addSQL(" and t1.audit_status = :auditStatus ");
        sql.addLikeSQL("  and t1.title like :title  ");
        sql.addLikeSQL(" and t2.nick_name like :nickName ");
        sql.addSQL(" ORDER BY audit_status,video_id DESC ");
        return CmfUserVideo.dao.paginate(page, limit, sql);
    }

    /**
     * 审核短视频
     */
    public Boolean audit(Long videoId) {
        CmfUserVideo cmfUserVideo = new CmfUserVideo();
//        cmfUserVideo.setVideoId(videoId);
//        cmfUserVideo.setAuditStatus("2");
//        cmfUserVideo.setAuditTime(new Date());
        return cmfUserVideo.update();
    }

    public Boolean reject(Long videoId) {
        CmfUserVideo cmfUserVideo = new CmfUserVideo();
//        cmfUserVideo.setVideoId(videoId);
//        cmfUserVideo.setAuditStatus("3");
//        cmfUserVideo.setAuditTime(new Date());
        return cmfUserVideo.update();
    }

    @Override
    public Integer cmfCount(Long userId) {
        StringBuilder str = new StringBuilder();
        str.append("select count(1) from cmf_user_video where uid=? ");
        return Db.queryInt(str.toString(), userId);
    }
}
